<template>
  <div>
    <div class="card">
      <div style="margin-bottom: 10px;">
        <el-table :data="data.tableData">
          <el-table-column label="序号" prop="id" width="70"></el-table-column>
          <el-table-column label="登录账户" prop="name"></el-table-column>
          <el-table-column label="登录IP" prop="ip"></el-table-column>
          <el-table-column label="登录地址" prop="address"></el-table-column>
          <el-table-column label="登录时间" prop="logintime"></el-table-column>
        </el-table>
      </div>
      <div class="card">
        <el-pagination
          background
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[5, 10, 20, 50, 100]"
          @current-change="handelCurrentChange"
          @size-change="handleSizeChange"
          v-model:current-page="data.pageNum"
          v-model:page-size="data.pageSize"
          :total="data.total"
        />
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive, onMounted } from 'vue'
import request from "@/utils/request"

const data = reactive({
  tableData: [],
  pageNum: 1,
  pageSize: 10,
  total: 0
})

// 加载登录日志数据
const load = () => {
  request.get("/loginlog/selectPage", {
    params: {
      pageNum: data.pageNum,
      pageSize: data.pageSize
    }
  }).then(res => {
    data.tableData = res.data?.list || []
    data.total = res.data?.total || 0
  })
}

// 分页处理函数
const handelCurrentChange = (pageNum) => {
  data.pageNum = pageNum
  load()
}

const handleSizeChange = (pageSize) => {
  data.pageSize = pageSize
  load()
}

// 页面加载时获取数据
onMounted(() => {
  load()
})
</script>

<style scoped>
.card {
  padding: 10px;
  margin-bottom: 10px;
  background-color: white;
  border-radius: 4px;
}
</style>]]>